package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/updateAttendance")
public class update_attendance extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html;charset=utf-8");
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");

        PrintWriter out = response.getWriter();
        HttpSession session = request.getSession();

        String stu_id = request.getParameter("stu_id");
        String attendance_time = request.getParameter("attendance_Time");
        String teacherId = request.getParameter("teacherId");
        String status = request.getParameter("attendanceStatus");

        try{
            dao.AttendanceDao attendanceDao = new dao.AttendanceDao();
            attendanceDao.updateAttendance(stu_id, attendance_time, teacherId, status);
        }
        catch (Exception e){
            out.print(e);
    }

        session.setAttribute("attendance_time", attendance_time);
        session.setAttribute("teacherId", teacherId);
        response.sendRedirect("one_page_attendance_detail");
    }





}
